# -*- coding: utf-8 -*-


"""
配置文件工具
"""
from configparser import ConfigParser

from utils.file_utils import FileUtils


class ConfigTools(object):
    @staticmethod
    def get_value(section, key, def_val=""):
        try:
            if FileUtils.file_exists('config.ini'):
                config = ConfigParser()
                config.read(FileUtils.get_new_path('config.ini'), encoding='utf-8')
                value = config.get(section, key)
                return value
            else:
                # raise Exception('配置文件不存在')
                print("配置文件不存在")
                return def_val
        except Exception as e:
            # raise Exception(f"获取配置文件错误: {e}")
            print(f"获取配置文件错误: {e}")
            return def_val

    @staticmethod
    def set_file():
        # 创建一个ConfigParser对象
        config = ConfigParser()
        try:
            pass
        except Exception as e:
            pass
        # 写入INI文件
        try:
            with open(FileUtils.get_new_path('config.ini'), 'w', encoding='utf-8') as configfile:
                config.write(configfile)
        except Exception as e:
            raise Exception(f"更新ini文件失败: {e}")


if __name__ == '__main__':
    print("Python")
